package com.lb.jwitter.action;


import java.util.List;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import com.lb.jwitter.util.ApplicationContextProvider; 
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; 
import org.springframework.test.context.ContextConfiguration;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.lb.jwitter.service.ConditionReport; 
 import java.util.Map; 
import com.opensymphony.xwork2.ActionContext; 
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblQuyenChiTietService;import com.lb.jwitter.service.TblTaiKhoan;import com.lb.jwitter.service.TblQLDTTXAMonHoc;
import com.lb.jwitter.service.TblQLDTTXAMonHocService;
import com.lb.jwitter.service.TblQLDTTXADMBoMon;
import com.lb.jwitter.service.TblQLDTTXADMBoMonService;

import com.lb.jwitter.service.TblQLDTTXAMonHocTienQuyet;
import com.lb.jwitter.service.TblQLDTTXAMonHocTienQuyetService;

import com.lb.jwitter.service.TblQLDTTXAMonHocBatBuoc;
import com.lb.jwitter.service.TblQLDTTXAMonHocBatBuocService;

import com.lb.jwitter.service.TblQLDTTXAMonHocSongHanh;
import com.lb.jwitter.service.TblQLDTTXAMonHocSongHanhService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblQLDTTXAMonHocEditFormAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private int id; 
    public void setId(int id) { this.id = id; }

    public int getId() { return id; }

    private TblQLDTTXAMonHoc tblQLDTTXAMonHoc; 
    public TblQLDTTXAMonHoc getTblQLDTTXAMonHoc() { 
        return tblQLDTTXAMonHoc; 
    } 
    private List<TblQLDTTXAMonHoc> tblQLDTTXAMonHocs; 
    public List<TblQLDTTXAMonHoc>  getTblQLDTTXAMonHocs() {
         return tblQLDTTXAMonHocs; 
      } 

    private TblQLDTTXAMonHocService tblQLDTTXAMonHocService; 

    private List<TblQLDTTXADMBoMon> tblQLDTTXADMBoMons; 
    public List<TblQLDTTXADMBoMon>  getTblQLDTTXADMBoMons(){ 
              return tblQLDTTXADMBoMons; 
     } 

    private TblQLDTTXADMBoMonService tblQLDTTXADMBoMonService; 

    private List<TblQLDTTXAMonHocTienQuyet> tblQLDTTXAMonHocTienQuyets; 
    public List<TblQLDTTXAMonHocTienQuyet>  getTblQLDTTXAMonHocTienQuyets(){ 
              return tblQLDTTXAMonHocTienQuyets; 
     } 

    private TblQLDTTXAMonHocTienQuyetService tblQLDTTXAMonHocTienQuyetService; 

    private List<TblQLDTTXAMonHocBatBuoc> tblQLDTTXAMonHocBatBuocs; 
    public List<TblQLDTTXAMonHocBatBuoc>  getTblQLDTTXAMonHocBatBuocs(){ 
              return tblQLDTTXAMonHocBatBuocs; 
     } 

    private TblQLDTTXAMonHocBatBuocService tblQLDTTXAMonHocBatBuocService; 

    private List<TblQLDTTXAMonHocSongHanh> tblQLDTTXAMonHocSongHanhs; 
    public List<TblQLDTTXAMonHocSongHanh>  getTblQLDTTXAMonHocSongHanhs(){ 
              return tblQLDTTXAMonHocSongHanhs; 
     } 

    private TblQLDTTXAMonHocSongHanhService tblQLDTTXAMonHocSongHanhService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
 public String execute() throws Exception 
{ 
 try{ 	
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_QLDTTXA_MonHoc", "sua")){ 
        return "noprivilege"; 
    }        
    tblQLDTTXAMonHocService = (TblQLDTTXAMonHocService) context.getBean("tbl_QLDTTXA_MonHocClient"); 
        tblQLDTTXADMBoMonService = (TblQLDTTXADMBoMonService) context.getBean("tbl_QLDTTXA_DM_BoMonClient"); 

        tblQLDTTXAMonHocTienQuyetService = (TblQLDTTXAMonHocTienQuyetService) context.getBean("tbl_QLDTTXA_MonHocTienQuyetClient"); 

        tblQLDTTXAMonHocBatBuocService = (TblQLDTTXAMonHocBatBuocService) context.getBean("tbl_QLDTTXA_MonHocBatBuocClient"); 

        tblQLDTTXAMonHocSongHanhService = (TblQLDTTXAMonHocSongHanhService) context.getBean("tbl_QLDTTXA_MonHocSongHanhClient"); 

        
        tblQLDTTXAMonHoc = tblQLDTTXAMonHocService.gettblQLDTTXAMonHoc(new Long(id)); 
        tblQLDTTXADMBoMons = tblQLDTTXADMBoMonService.findAlltblQLDTTXADMBoMon(0, 0);


        
    List<ConditionReport> cons = new ArrayList<ConditionReport>(); 

//        if (id != 0) 
//        { 
//            ConditionReport con = new ConditionReport(); 
//            con.setCol("boMonId.id"); 
//            con.setValue1(tblQLDTTXAMonHoc.getBoMonId().getId()); 
//            con.setOperator("eq"); 
//            cons.add(con); 
//        } 
  
        tblQLDTTXAMonHocs = tblQLDTTXAMonHocService.findtblQLDTTXAMonHocByCondition(cons, 0, 0);

	   cons.clear();
	   if (id != 0) 
	   { 
	       ConditionReport con = new ConditionReport(); 
	       con.setCol("monHocId.id"); 
	       con.setValue1(new Long(id)); 
	       con.setOperator("eq"); 
	       cons.add(con); 
	   } 
	   
	   tblQLDTTXAMonHocTienQuyets = tblQLDTTXAMonHocTienQuyetService.findtblQLDTTXAMonHocTienQuyetByCondition(cons, pageSize, page); 
	
	   tblQLDTTXAMonHocBatBuocs = tblQLDTTXAMonHocBatBuocService.findtblQLDTTXAMonHocBatBuocByCondition(cons, pageSize, page); 
	
	   tblQLDTTXAMonHocSongHanhs = tblQLDTTXAMonHocSongHanhService.findtblQLDTTXAMonHocSongHanhByCondition(cons, pageSize, page); 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi EditForm tbl_QLDTTXA_MonHoc Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
